package com.zzyl.nursing.service.member.Impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.utils.SecurityUtils;
import com.zzyl.nursing.domain.Reservation1;
import com.zzyl.nursing.mapper.member.MemberReservationMapper;
import com.zzyl.nursing.service.member.IMemberReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MemberReservationserviceImpl extends ServiceImpl<MemberReservationMapper, Reservation1> implements IMemberReservationService {

    @Autowired
    private  MemberReservationMapper memberReservationMapper;

    @Override
    public Long cancelledCount() {
        //获取当前用户登录id
        Long userId = SecurityUtils.getUserId();
        //获取当天开始和结束时间
        DateTime startTime = DateUtil.beginOfDay(DateUtil.date());
        DateTime endTime = DateUtil.endOfDay(DateUtil.date());

        //sql:select * from reservation where status = 2
        // and update_by = #{userId} and update_time between #{start} and #{end};
        LambdaQueryWrapper<Reservation1> in = new LambdaQueryWrapper<Reservation1>()
                .eq(Reservation1::getStatus, 2)
                .eq(Reservation1::getUpdateBy, userId)
                .eq(Reservation1::getUpdateTime, startTime)
                .in(Reservation1::getUpdateTime, endTime);
        return  memberReservationMapper.selectCount(in);
    }
}
